package com.quasar.hpatient.view.adapter;

import android.text.TextPaint;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.R;
import com.quasar.hpatient.model.custommodel.TemperatureTableItem;
import com.quasar.hpatient.utils.Spanny;

import java.util.List;

/**
 * author : 许建宏
 * Date: 2017/10/26 0026
 * View:体温
 */

public class TemperatureAdapter extends BaseMultiItemQuickAdapter<TemperatureTableItem, BaseViewHolder> {

    public TemperatureAdapter(List<TemperatureTableItem> data) {
        super(data);
        addItemType(TemperatureTableItem.HEAD, R.layout.widget_temperature_medicine);
        addItemType(TemperatureTableItem.BODY, R.layout.widget_temperature_medicine);
    }

    @Override
    protected void convert(BaseViewHolder helper, TemperatureTableItem item) {

        Spanny spanny = new Spanny();
        switch (helper.getItemViewType()) {
            case TemperatureTableItem.HEAD:
                if(item.getDailyitemName()!=null || item.getDailyitemName().length()>0){
                    helper.setText(R.id.tv_company,item.getDailyitemName());
                }
                if(item.getDailyitemDose()!=null || item.getDailyitemDose().length()>0){
                    StringBuffer stringBuffer=new StringBuffer();
                    stringBuffer.append(item.getDailyitemDose());
                    helper.setText(R.id.tv_val,stringBuffer.toString());
                }
                break;
            case TemperatureTableItem.BODY:
                helper.setText(R.id.tv_time, item.getLogTime());
                helper.setText(R.id.tv_val, item.getLogValue() + "");

                TextView tv_company=helper.getView(R.id.tv_company);
                TextPaint tp = tv_company.getPaint();
                if(item.getStats().equals("0")){
                    spanny.append("正常", new ForegroundColorSpan(color(R.color.btcolor)));
                }else if(item.getStats().equals("1")){
                    spanny.append("低热", new ForegroundColorSpan(color(R.color.red)));
                    tp.setFakeBoldText(true);
                }else if(item.getStats().equals("2")){
                    spanny.append("高热", new ForegroundColorSpan(color(R.color.red)));
                    tp.setFakeBoldText(true);
                }else if(item.getStats().equals("3")){
                    spanny.append("心动过缓", new ForegroundColorSpan(color(R.color.red)));
                    tp.setFakeBoldText(true);
                }else if(item.getStats().equals("4")){
                    spanny.append("心动过速", new ForegroundColorSpan(color(R.color.red)));
                    tp.setFakeBoldText(true);
                }else if(item.getStats().equals("-1")){
                    spanny.append("体温过低", new ForegroundColorSpan(color(R.color.red)));
                    tp.setFakeBoldText(true);
                }
                tv_company.setText(spanny);
                break;
        }
        helper.addOnClickListener(R.id.tv_val);
        helper.addOnLongClickListener(R.id.tv_val);
    }

    private int color(int value) {
        return MainAppliaction.getInstance().getResources().getColor(value);
    }
}
